import {reactive, ref, toRefs, toRef, computed, 
    watch,watchEffect,watchPostEffect,
  defineExpose, defineProps,withDefaults,
  onBeforeMount,onMounted,onBeforeUpdate,onUpdated,
  onBeforeUnmount,
  onUnmounted
} from 'vue'

import axios from 'axios'
 
export default function(){
    let dogList = reactive([
        'https://images.dog.ceo//breeds//pembroke//n02113023_4391.jpg'
      ])
      
      const imageurl = 'https://dog.ceo/api/breed/pembroke/images/random';
      const imageurl2 = 'https://dog.ceo/api/breeds/image/random'
      
      
      const oneMoreDog = () => {
        axios.get(imageurl).then(res => {
          dogList.push(res.data.message)
        }).catch(error => {
          if (error.response) {
          // 服务器返回了状态码
          const { status, data } = error.response;
          alert(`请求失败，状态码: ${status}, 错误信息: ${data.message || '未知错误'}`);
        } else if (error.request) {
          // 请求已发出但没有收到响应
          alert('请求已发出但没有收到响应');
        } else {
          // 发生在设置请求时的错误
          alert(`请求配置错误: ${error.message}`);
        }
        return Promise.reject(error);
        })
      }
      
      // axios统一拦截器捕获异常,并弹出alert
      
      async function oneMoreDog2(){
         const result = await axios.get(imageurl2)
         return result.data.message
      }

      return {dogList,oneMoreDog}
}
